<?php
/**
 * Created by PhpStorm.
 * User: cscjj2008
 * Date: 15-3-10
 * Time: 上午10:07
 */

class Mountrecord extends \Eloquent
{
    protected $fillable = [];


    public function mount(){
        return $this->belongsTo('Mount');
    }
    public function customer(){
        return $this->belongsTo('Customer');
    }

    /**
     * @param $mount_id 装机id
     * @param $action 变化操作
     * @param null $customer_id 用户id
     * @param null $invite_id 邀请人id
     */
    public static function new_record($mount_id,$action,$customer_id = null , $invite_id = null){
        if($customer_id == null){
            $mount = Mount::find($mount_id);
            $customer_id = $mount->customer_id;
        }
        if($invite_id == null){
            $customer = Customer::find($customer_id);
            $invite_id = $customer->invite_id;
        }
        $mountrecord = new Mountrecord();
        $mountrecord->mount_id = $mount_id;
        $mountrecord->action = $action;
        $mountrecord->customer_id = $customer_id;
        $mountrecord->invite_id = $invite_id;
        $mountrecord->save();

    }

}